//
// Created by Administrator on 2023/7/31.
//
#include <iostream>
#include <cmath>

using namespace std;

class Solution {
public:
    int pivotInteger(int n) {
        // x = sqrt((n*2+n)/2)
        int tar = (n*n+n)/2;
        int tmp =sqrt(tar);
        return tmp*tmp == tar?tmp :-1;
    }
};

int main() {
    Solution s;
    cout << s.pivotInteger(8) << endl;
    cout << s.pivotInteger(1) << endl;
    cout << s.pivotInteger(4) << endl;
}